#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

int com_int(const void* p1, const void* p2)
{
	return (*(int*)p1 - *(int*)p2);
}

void Swap(void* p1, void* p2, size_t width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char temp = *((char*)p1 + i);
		*((char*)p1 + i) = *((char*)p2 + i);
		*((char*)p2 + i) = temp;
	}
}

void Bobble_sort(void* base, size_t sz, size_t width, int (com)(const void*, const void*))
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (com((char*)base + j * width, (char*)base + (j + 1) * width) > 0)
			{
				Swap((char*)base + j * width, (char*)base + (j + 1) * width, width);
			}
		}
	}
}

void print(int arr[10], int sz)
{
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
}

int main()
{
	int arr[10] = { 10,9,8,7,6,5,4,3,2,1 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	Bobble_sort(arr, sz, sizeof(arr[0]), com_int);
	print(arr, sz);
	return 0;
}